sysroot: Track whether /run/ostree-booted exists
authorColin Walters <walters@verbum.org>
Mon, 12 Mar 2018 17:24:09 +0000 (13:24 -0400)
committerAtomic Bot <atomic-devel@projectatomic.io>
Thu, 15 Mar 2018 17:43:19 +0000 (17:43 +0000)
Prep for further work around deployment staging.

Closes: #1497
Approved by: jlebon

src/libostree/ostree-sysroot-private.h
src/libostree/ostree-sysroot.c

index 3ed6237bea53eba54e0b2bec1d366cf7ea19eb6f..cb4aac9d97e109ee5a68504ebb8c29301d1ec409 100644 (file)
@@ -50,6 +50,7 @@ struct OstreeSysroot {
   GLnxLockFile lock;
 
   gboolean loaded;
+  gboolean ostree_booted;
 
   gboolean is_physical; /* TRUE if we're pointed at physical storage root and not a deployment */
   GPtrArray *deployments;
index 2d12deb63e7ba10a4a7ab0e350a7a38cf0a4993b..3294e83d77c8eb2c3cd264e26ac2cf8e939bece3 100644 (file)
@@ -797,6 +797,16 @@ ostree_sysroot_load_if_changed (OstreeSysroot  *self,
   if (!ensure_repo (self, error))
     return FALSE;
 
+  /* If we didn't check already, see if we have the global ostree-booted flag;
+   * we'll use it to sanity check that we found a booted deployment for example.
+   */
+  if (!self->loaded)
+    {
+      if (!glnx_fstatat_allow_noent (AT_FDCWD, "/run/ostree-booted", NULL, 0, error))
+        return FALSE;
+      self->ostree_booted = (errno == 0);
+    }
+
   int bootversion = 0;
   if (!read_current_bootversion (self, &bootversion, cancellable, error))
     return FALSE;
@@ -852,6 +862,9 @@ ostree_sysroot_load_if_changed (OstreeSysroot  *self,
   if (!find_booted_deployment (self, deployments, &self->booted_deployment,
                                cancellable, error))
     return FALSE;
+  /* Sanity check; note the converse case is fine */
+  if (self->booted_deployment && !self->ostree_booted)
+    return glnx_throw (error, "Unexpected state: In a booted deployment but no /run/ostree-booted?");
 
   /* Determine whether we're "physical" or not, the first time we initialize */
   if (!self->loaded)